﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace project_phoenix.source
{
    public class AnimationManager
    {
        private string textureName;
        private Texture2D texture;

        // the current animation we are drawing
        private Animation currentAnimation = null;

        // this will store all of the animations for this instance of the character
        private List<Animation> animations = new List<Animation>();


        public AnimationManager(string filePath)
        {
            texture = GameGlobals.Content.Load<Texture2D>(filePath);
        }

        // adds an animation to our list
        public bool AddAnimation(Animation anim)
        {
            if (anim != null)
            {
                animations.Add(anim);
                return true;
            }
            return false;
        }

        public void PlayAnimation(Animation animation)
        {
            // if we are playing this anim, then skip this
            if (animation != currentAnimation)
            {
                currentAnimation = animation;
                ResetAnimation();
            }
        }

        public void PlayAnimation(Animation.animType type)
        {
            foreach (Animation anim in animations)
            {
                if (anim.Name == type.ToString())
                {
                    PlayAnimation(anim);
                    break;
                }
            }
        }

        public void ResetAnimation()
        {
            if (currentAnimation != null)
            {
                // resets our current animation
                currentAnimation.CurrentFrame = 0;
                currentAnimation.IsDone = false;
            }
        }

        // stops our current animation
        public void StopAnimation()
        {
            currentAnimation = null;
        }

        public void UpdateAnimation(GameTime gt, Vector2 dir)
        {
            currentAnimation.Update(gt, dir);
        }

        public void Draw(Vector2 position)
        {
            GameSystems.Graphics.DrawImage(texture, position, currentAnimation.SourceRectangle, Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f);
        }


        #region Properties
        public Animation Animation
        {
            get { return currentAnimation; }
        }
        #endregion
    }
}
